package org.com.cis.cf.measure;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

import org.com.cis.cf.util.SortByTrue;
import org.com.cis.cf.util.TestPoint;

public class IIDCGScorer extends MetricScorer { 
	
	public double score(ArrayList<TestPoint> rateList, boolean k_flag) 
	{
		double score = 0.0;

		int length = rateList.size(), i;
		
		@SuppressWarnings("unchecked")
		Comparator<TestPoint> sortByTrue = new SortByTrue();
		Collections.sort(rateList, sortByTrue);

		for( i = 0; i != length; ++i){
			if( i == k && k_flag)
				break;
			score += ((Math.pow(2, rateList.get(i).getTrue()))-1) / (Math.log(2+i));
		}
		return score;
	}
}
